package com.lanling.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lanling.eduservice.entity.EduCourse;
import com.lanling.eduservice.entity.EduTeacher;
import com.lanling.eduservice.orther.R;
import com.lanling.eduservice.service.EduCourseService;
import com.lanling.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 胡振华
 * @date 2020-11-18 19:41
 */
@RestController
@CrossOrigin
@RequestMapping("/eduservice/indexfront")
public class IndexFrontController {

    @Autowired
    private EduCourseService eduCourseService;

    @Autowired
    private EduTeacherService eduTeacherService;



    @GetMapping("index")
    public R index(){
        //热度前8的课程
        QueryWrapper<EduCourse> courseWrapper = new QueryWrapper<>();
        courseWrapper.orderByDesc("buy_count");//销售数量
        courseWrapper.last("limit 8");
        List<EduCourse> eduCourses = eduCourseService.list(courseWrapper);

        //前4的名师
        QueryWrapper<EduTeacher> teacherWrapper = new QueryWrapper<>();
        teacherWrapper.orderByDesc("id");
        teacherWrapper.last("limit 4");
        List<EduTeacher> eduTeachers = eduTeacherService.list(teacherWrapper);

        return R.ok().data("eduCourses",eduCourses).data("eduTeachers",eduTeachers);
    }

}